package com.crm.asset.service;

import com.crm.asset.dto.CustDTO;
import com.crm.asset.entity.ProdInst;
import com.crm.asset.feign.client.CustFeignClient;
import com.crm.asset.mapper.ProdInstMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProdInstService {
    @Autowired
    private ProdInstMapper prodInstMapper;
    @Autowired
    private CustFeignClient custFeignClient;
    public List<ProdInst> query(Long prodId, Long custId, String accNum) {
        List<ProdInst>  list=prodInstMapper.query(prodId,custId,accNum);
        for(ProdInst prodInst:list){
          CustDTO custDTO= custFeignClient.get(prodInst.getCustId());
          if(custDTO!=null) {
              prodInst.setCustName(custDTO.getCustName());
          }
        }
        return list;
    }
    public Long add(ProdInst prodInst) {
        return  prodInstMapper.add(prodInst);
    }
    public int update(ProdInst prodInst){
        return prodInstMapper.update(prodInst);
    }
    public int delete(Long id){
        return prodInstMapper.delete(id);
    }
    public ProdInst get(Long id){
        return prodInstMapper.get(id);
    }

}
